package com.cus.shd.sharingjdbc.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.cus.shd.sharingjdbc.mappers.RecordOrderLogMapper;
import com.cus.shd.sharingjdbc.model.RecordOrderLog;
import com.cus.shd.sharingjdbc.service.RecordOrderLogService;
import com.cus.shd.sharingjdbc.utils.RandomUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.DependsOn;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 *
 * @author lcc
 * @since 2021-10-30
 */
@Service
public class RecordOrderLogServiceImpl extends ServiceImpl<RecordOrderLogMapper, RecordOrderLog> implements RecordOrderLogService {

    @Autowired
    private RecordOrderLogMapper recordOrderLogMapper;

    @Override
    public RecordOrderLog queryByOrderDeliveryId(Long orderDeliveryId) {
        return recordOrderLogMapper.queryByOrderDeliveryId(orderDeliveryId);
    }

    public Integer insert() {
        List<RecordOrderLog> recordOrderLogs = new ArrayList<>();
        for(int i = 0;i < 100;i++){
            RecordOrderLog recordOrderLog = new RecordOrderLog();
            Long uniqueKey = Long.parseLong(RandomUtils.getRandomNo("16",16));
            //这里只测试分片键
            recordOrderLog.setId(uniqueKey);
            recordOrderLog.setOrderDeliveryId(uniqueKey);
            recordOrderLog.setEnabledFlag(1);
            recordOrderLogs.add(recordOrderLog);
        }
        this.saveBatch(recordOrderLogs);
        return 1;
    }

    @Override
    public Integer createTable(String tableName) {
        return getBaseMapper().createNewTable(tableName);
    }

    @Override
    public Integer test() {
        return 1;
    }
}
